import com.hanxu.dao.UserMapper;
import com.hanxu.pojo.User;
import com.hanxu.utlis.MybatisUtils;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;

public class Mytest5 {

   static   Logger logger = Logger.getLogger(UserMapper.class);

    @Test
    public void test(){
        SqlSession sqlsession = MybatisUtils.getSqlsession();
        UserMapper mapper = sqlsession.getMapper(UserMapper.class);
        List<User> userList = mapper.getUserList();
        for (User user : userList) {
            System.out.println(user);
        }


        sqlsession.close();
    }


    /**
     * 日志输出方法
     */
    @Test
    public void log4jsc(){
        logger.info("info输出");
        logger.debug("debug输出");
        logger.error("error输出");

    }

    /**
     * 使用limit实现分页
     */
    @Test
    public void  getUserByLimit(){
        SqlSession sqlsession = MybatisUtils.getSqlsession();
        UserMapper mapper = sqlsession.getMapper(UserMapper.class);

        HashMap<String, Integer> map = new HashMap<>();

//        这里的名字不能随便乱写，在usermapper中使用的startIndex,pageSize
        map.put("startIndex",0);
        map.put("pageSize",2);

        List<User> userByLimit = mapper.getUserByLimit(map);
        for (User user : userByLimit) {
            System.out.println(user);
        }

        sqlsession.close();


    }


    /**
     * 使用rowbound实现分页
     */
    @Test
    public void  getUserByRowBound(){
        SqlSession sqlsession = MybatisUtils.getSqlsession();

        RowBounds rowBounds = new RowBounds(1, 3);

        List<User> user = sqlsession.selectList("com.hanxu.dao.UserMapper.getUserByRowBound", null, rowBounds);
        for (User user1 : user) {
            System.out.println(user1);
        }

        sqlsession.close();
    }

}

